from vnpy_datarecorder import RecorderEngine, DataRecorderApp

from vnpy.event import EventEngine
from vnpy.trader.constant import Exchange
from vnpy.trader.engine import MainEngine
from vnpy.trader.object import ContractData
from vnpy.trader.ui import MainWindow, create_qapp

from vnpy_rpcservice import RpcGateway
from vnpy_ctastrategy import CtaStrategyApp


def main():
    """
    测试 - 行情录制，单个合约行情
    Returns:

    """
    event_engine = EventEngine()

    main_engine = MainEngine(event_engine)
    # main_engine.add_app(CtaStrategyApp)
    rpc_gateway:RpcGateway=main_engine.add_gateway(RpcGateway)

    rpc_gateway.connect({
        "主动请求地址": "tcp://localhost:2014",
        "推送订阅地址": "tcp://localhost:4102"
    })
    main_engine.write_log('RPC gateway started')

    record_engine:RecorderEngine = main_engine.add_app(DataRecorderApp)
    record_engine.register_event()
    record_engine.add_tick_recording("au2506.SHFE")
    contract: ContractData = ContractData(gateway_name="RPC", exchange=Exchange.SHFE, symbol="au2506", name="contract_test", product=None, size=0, pricetick=None)
    record_engine.subscribe(contract)
    main_engine.write_log('record engine started')



if __name__ == "__main__":
    main()
